package collectdemo13.set.treeset;

import java.util.Iterator;
import java.util.TreeSet;
import java.util.Set;
class Human implements Comparable<Human>
{
	private String name = null;
	private int age = 0;
	
	public Human(String name, int age)
	{
		super();
		this.name = name;
		this.age = age;
	}
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public int getAge()
	{
		return age;
	}
	public void setAge(int age)
	{
		this.age = age;
	}
	@Override
	public String toString()
	{
		return "Person [age=" + age + ", name=" + name + ", getAge()=" + getAge() + ", getName()=" + getName();
	}
	public int compareTo(Human human)
	{
		// TODO Auto-generated method stub
		int temp = 0;
		if(this.getAge() < human.getAge())
		{
			temp = -1;
		}
		else if(this.getAge() == human.getAge())
		{
			temp = this.getName().compareToIgnoreCase(human.getName());
		}
		else
		{
			temp = 1;
		}
		return temp;
	}
	
}

public class DelDuplicatedTreeSetDemo05
{
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		Set<Human> set = new TreeSet<Human>();
		Human [] per = new Human[10];
		for(int i = 0;i<10;i++)
		{
			per[i] = new Human("i",i);
			set.add(per[i]);
		}
		set.add(new Human("张三",30));
		set.add(new Human("张三",30));
		set.add(new Human("李四",30));
		set.add(new Human("王五",20));
		Iterator<Human> it =  set.iterator();
		while(it.hasNext())
		{
			Human temp = (Human)it.next();
			System.out.println("增加后的Person是："+temp);
		}
	}

}
